package com.linln.modules.ad.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Where;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.linln.common.enums.AdEnum;
import com.linln.common.enums.DayEnum;
import com.linln.common.enums.StatusEnum;
import com.linln.common.utils.StatusUtil;
import com.linln.modules.member.domain.MemberInfo;
import com.linln.modules.system.domain.User;

import lombok.Data;

/**
 * @author hct
 * @date 2019/09/12
 */
@Data
@Entity
@Table(name="adinfo")
@EntityListeners(AuditingEntityListener.class)
@Where(clause = StatusUtil.NOT_DELETE)
public class AdInfo implements Serializable {
    // 主键ID
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Long id;
    // 所属区域
    private String area;
    
    private String areaname;
    
    // 首页显示图片
    private String img;
    // 详情图片
    private String detailimg;    
    
    // 广告类型 1代表首页/2代表商户
    private Integer adtypeid;
    
    private String orderId;
    private String orderCode;
    //广告类型的内容
    @Transient
    private String adtype;
    
 // 联系人
    private String pushName;
    
    // 联系电话
    private String pushPhone;
    
    private String title;   
    
    private String city;   

    //详情
    private String details;
    //地址
    private String address;
    
    public String getAdtype() {
		return AdEnum.getVal(adtypeid); 
	}
    
    // 排序
    private Integer num;
    
    //广告开始时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
   	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
    private Date startTime;
    //广告结束时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
    private Date endTime;
    
    private Integer dayCount; 
    
    //广告时长   1=7天/2=半个月/3=1个月/4=1季度/5=半年/6=1年
    private Integer day; 
    
    //广告时长内容
    @Transient
    private String dayValue;
    
    public String getDayValue() {
		return DayEnum.getVal(day); 
	}
    
    //广告支付费用
    private Double fee;    
    //广告支付状态  0是代付款待审核 1是已付款待审核  2 已拒绝已退款
    private Integer payStatus;    
    //0待审核 1已通过 2已拒绝
    private  Integer adStatus; 
    //阅读数
    private  Integer readnum; 
    
    
    //申请人
  //  private Long memberId;
    @ManyToOne(fetch=FetchType.LAZY)
    @NotFound(action=NotFoundAction.IGNORE)
    @JoinColumn(name="member_id")
    private MemberInfo member;
    //代理商信息
    private Long agentId;
    //代理商审核时间
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
   
    private Date shenheTime;
    
    // 创建时间
    @CreatedDate
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
   
    private Date createDate;
    // 更新时间
    @LastModifiedDate
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
   
    private Date updateDate;    
    //
    @CreatedBy
    @ManyToOne(fetch=FetchType.LAZY)
    @NotFound(action=NotFoundAction.IGNORE)
    @JoinColumn(name="create_by")
    @JsonIgnore
    private User createBy;
    // 修改人
    @LastModifiedBy
    @ManyToOne(fetch=FetchType.LAZY)
    @NotFound(action=NotFoundAction.IGNORE)
    @JoinColumn(name="update_by")
    @JsonIgnore
    private User updateBy;
    // 状态
    private Byte status = StatusEnum.OK.getCode();
}